Skip to content

Added call_tool #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged

Added call_tool #153

merged 1 commit into from
Jun 5, 2025

Conversation

serg33v
Copy link
Collaborator

@serg33v serg33v commented Jun 5, 2025

Summary by CodeRabbit

  • Refactor
    • Improved analytics event capture logic for better modularity and support for multiple configurations. No changes to user-facing functionality.
  • Chores
    • Internal improvements to event tracking infrastructure.

@serg33v serg33v requested a review from wonderwhy-er June 5, 2025 14:28
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes refactor analytics event capture logic by introducing a generic capture function that accepts a URL parameter, allowing multiple Google Analytics configurations. Two new exported functions, capture_call_tool and capture, are added, each using distinct GA settings. The server handler is updated to use capture_call_tool for specific requests.

Changes

File(s) Change Summary
src/utils/capture.ts Refactored event capture logic: introduced captureBase, added capture_call_tool and new capture functions; removed global GA constants and modularized configuration.
src/server.ts Updated import to include capture_call_tool; replaced previous capture call with capture_call_tool in request handler.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant CaptureUtils

    Client->>Server: CallToolRequest (with event & payload)
    Server->>CaptureUtils: capture_call_tool(event, payload)
    CaptureUtils->>CaptureUtils: Build GA payload, check telemetry
    CaptureUtils->>GoogleAnalytics: Send event via HTTPS
    Server-->>Client: Response
Loading

Poem

In the warren, we capture with care,
Analytics now split, configs laid bare.
Call tools hop with a brand-new track,
Modular logic—no turning back!
With every event, a bunny’s delight,
Hopping through data, all day and night.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/utils/capture.ts (1)

199-199: Remove unused debug URL variables.

The GA_DEBUG_BASE_URL variables are defined but never used. Consider removing them or implementing debug functionality if needed.

-    const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;    

Also applies to: 207-207

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c579959 and 3a9f824.

📒 Files selected for processing (2)
  • src/server.ts (2 hunks)
  • src/utils/capture.ts (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/server.ts (1)
src/utils/capture.ts (1)
  • capture_call_tool (195-201)
src/utils/capture.ts (1)
src/config-manager.ts (1)
  • configManager (212-212)
🪛 Gitleaks (8.26.0)
src/utils/capture.ts

197-197: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


205-205: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (5)
src/utils/capture.ts (3)

78-78: Good refactoring to parameterize the capture URL.

The function signature change to accept a captureURL parameter is a solid design improvement that enables multiple GA configurations.


84-84: Condition correctly updated for parameterized URL.

The logic properly checks for the presence of the captureURL parameter instead of hardcoded credentials.


162-162: HTTPS request correctly uses parameterized URL.

The implementation properly utilizes the passed captureURL parameter for the analytics request.

src/server.ts (2)

40-40: Import statement correctly updated.

The addition of capture_call_tool to the import statement properly reflects the new function usage.


393-395: Function call correctly changed to use specific capture function.

The change from capture to capture_call_tool appropriately uses the specialized function for call tool events, which aligns with the modular analytics approach.

Comment on lines +203 to +210
export const capture = async (event: string, properties?: any) => {
const GA_MEASUREMENT_ID = 'G-NGGDNL0K4L'; // Replace with your GA4 Measurement ID
const GA_API_SECRET = '5M0mC--2S_6t94m8WrI60A'; // Replace with your GA4 API Secret
const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;

return await captureBase(GA_BASE_URL, event, properties);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical security issue: Hardcoded API credentials exposed in source code.

Similar to the capture_call_tool function, this implementation exposes sensitive credentials in the source code. Move these to environment variables.

-export const capture = async (event: string, properties?: any) => {
-    const GA_MEASUREMENT_ID = 'G-NGGDNL0K4L'; // Replace with your GA4 Measurement ID
-    const GA_API_SECRET = '5M0mC--2S_6t94m8WrI60A'; // Replace with your GA4 API Secret
-    const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
-    const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
-
-    return await captureBase(GA_BASE_URL, event, properties);
-}
+export const capture = async (event: string, properties?: any) => {
+    const GA_MEASUREMENT_ID = process.env.GA_MEASUREMENT_ID || '';
+    const GA_API_SECRET = process.env.GA_API_SECRET || '';
+    
+    if (!GA_MEASUREMENT_ID || !GA_API_SECRET) {
+        console.warn('GA credentials not configured for capture');
+        return;
+    }
+    
+    const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
+    return await captureBase(GA_BASE_URL, event, properties);
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const capture = async (event: string, properties?: any) => {
const GA_MEASUREMENT_ID = 'G-NGGDNL0K4L'; // Replace with your GA4 Measurement ID
const GA_API_SECRET = '5M0mC--2S_6t94m8WrI60A'; // Replace with your GA4 API Secret
const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
return await captureBase(GA_BASE_URL, event, properties);
}
export const capture = async (event: string, properties?: any) => {
const GA_MEASUREMENT_ID = process.env.GA_MEASUREMENT_ID || '';
const GA_API_SECRET = process.env.GA_API_SECRET || '';
if (!GA_MEASUREMENT_ID || !GA_API_SECRET) {
console.warn('GA credentials not configured for capture');
return;
}
const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
return await captureBase(GA_BASE_URL, event, properties);
}
🧰 Tools
🪛 Gitleaks (8.26.0)

205-205: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
In src/utils/capture.ts around lines 203 to 210, the GA_MEASUREMENT_ID and
GA_API_SECRET are hardcoded, exposing sensitive credentials. Remove these
hardcoded values and instead read them from environment variables using
process.env, ensuring the credentials are not stored directly in the source
code. Update the GA_BASE_URL and GA_DEBUG_BASE_URL to use these environment
variables accordingly.

Comment on lines +195 to +201
export const capture_call_tool = async (event: string, properties?:any) => {
const GA_MEASUREMENT_ID = 'G-35YKFM782B'; // Replace with your GA4 Measurement ID
const GA_API_SECRET = 'qM5VNk6aQy6NN5s-tCppZw'; // Replace with your GA4 API Secret
const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
return await captureBase(GA_BASE_URL, event, properties);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical security issue: Hardcoded API credentials exposed in source code.

The Google Analytics API secret and measurement ID are hardcoded in the source code, which poses a significant security risk. These credentials should be stored in environment variables or a secure configuration system.

-export const capture_call_tool = async (event: string, properties?:any) => {
-    const GA_MEASUREMENT_ID = 'G-35YKFM782B'; // Replace with your GA4 Measurement ID
-    const GA_API_SECRET = 'qM5VNk6aQy6NN5s-tCppZw'; // Replace with your GA4 API Secret
-    const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
-    const GA_DEBUG_BASE_URL = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;    
-    return await captureBase(GA_BASE_URL, event, properties);
-}
+export const capture_call_tool = async (event: string, properties?:any) => {
+    const GA_MEASUREMENT_ID = process.env.GA_CALL_TOOL_MEASUREMENT_ID || '';
+    const GA_API_SECRET = process.env.GA_CALL_TOOL_API_SECRET || '';
+    
+    if (!GA_MEASUREMENT_ID || !GA_API_SECRET) {
+        console.warn('GA credentials not configured for call_tool capture');
+        return;
+    }
+    
+    const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
+    return await captureBase(GA_BASE_URL, event, properties);
+}
🧰 Tools
🪛 Gitleaks (8.26.0)

197-197: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
In src/utils/capture.ts around lines 195 to 201, the Google Analytics API secret
and measurement ID are hardcoded, exposing sensitive credentials. To fix this,
remove the hardcoded values and instead read GA_MEASUREMENT_ID and GA_API_SECRET
from environment variables using process.env. Update the code to use these
environment variables when constructing the GA_BASE_URL and GA_DEBUG_BASE_URL,
ensuring credentials are not stored directly in the source code.

@wonderwhy-er wonderwhy-er merged commit f31ae09 into main Jun 5, 2025
2 checks passed
@wonderwhy-er wonderwhy-er deleted the feat/ga2 branch June 5, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants